/**
 * @file   main.cpp
 * @author ywl <ywl@ywl-VirtualBox>
 * @date   Sat Dec 31 22:14:05 2022
 * 
 * @brief  A test program for five mixed operations calculator class.
 * 
 * 
 */

#include <iostream>
#include <string>
#include <fstream>
#include "calculator.h"

int main(int argc, char *argv[])
{
    std::ifstream file("input.txt");        
    // 构造一个计算器实例
    calculator cal;
    // 输出对计算器的介绍
    cal.get_info();

    if(file.is_open()){
	std::string input;
	// 记录结果
	double result;
	// 读入表达式
	while(std::getline(file,input))
	{
	    cal.init(input);
	    bool error = false; /// 判断是否有错误的例子
	    // 计算结果
	    try
	    {
		result = cal.calc();
	    }
	    catch(...)
	    {
		error = true;
	    }
	    // 输出结果
	    if(!error)
		std::cout << cal.get_infix() << " = " << result << std::endl;
	}
    }
    file.close();
    
    return 0;
}
